package com.cloud.spock.groovy.test

import static org.junit.Assert.*

import org.junit.runner.RunWith
import org.powermock.api.mockito.PowerMockito
import org.powermock.core.classloader.annotations.PrepareForTest
import org.powermock.modules.junit4.PowerMockRunner
import org.spockframework.runtime.Sputnik

import com.cloud.spock.test.MyService
import com.cloud.spock.test.MyServiceUtil

import spock.lang.Specification

@RunWith(PowerMockRunner.class)
@PowerMockRunnerDelegate(Sputnik.class)
@PrepareForTest([MyServiceUtil.class])
class MyServiceWithOtherRunner extends Specification{

    def id = "1024"
    def "测试难缠的static方法"(){
        given:
        PowerMockito.mockStatic(MyServiceUtil.class)
        PowerMockito.when(MyServiceUtil.getValue(id)).thenReturn("horrible")
        MyService myService = new MyService();
        when:
        String result = myService.getUtilValue(id)
        then:
        result == id+"horrible"
    }
}
